package cn.frank.framework.king.rest;

import cn.frank.framework.king.conf.logback.AppenderMarkerFilter;
import cn.frank.framework.king.domain.vo.Result;
import cn.hutool.core.date.DateUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: BaseRestController
 * @author: renjiangyang
 * @date 2024/7/30 15:41:57
 * @since 1.8
 */
@Api(tags = "基础")
@RestController
@Slf4j
@RequestMapping(value = "/api")
public class BaseKingRestController {

    /**
     * 公共方法，获取request
     */
    public HttpServletRequest getRequest() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (attributes == null) {
            throw new IllegalStateException("当前线程中没有找到 ServletRequestAttributes，请确保在 Web 请求上下文中调用此方法");
        }
        HttpServletRequest request = attributes.getRequest();
        return request;
    }

    /**
     * 测试接口
     * @param message
     * @return
     */
    @ApiOperation(value = "测试")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParam(name = "message", value = "信息", dataType = "String", defaultValue = "hello", required = true)
    @GetMapping(value = "/frank")
    public Result<String> mySync(String message) {
        log.info("123");
        log.info(AppenderMarkerFilter.alone, "abc");
        return Result.success(DateUtil.now() + " success ");
    }

}
